﻿// --------------------------------------------------------------------------------------
// <copyright file="ResourceService.cs" company="NGroup">
// Copyright (c) NGroup. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------
// <history>
//     <change who="Bui Thanh Nam" date="2014.09.17">Create</change>
// </history>
// --------------------------------------------------------------------------------------

namespace NGroup.VTL.Service
{
    using System.Collections.Generic;
    using NGroup.VTL.Core.Const;
    using NGroup.VTL.DAL;
    using NGroup.VTL.Models;
    using NGroup.VTL.Resources;
    using NGroup.VTL.Service.Abstraction;

    public class ResourceService:IResourceService
    {
        private ResourceDAO _resourceDAO;

        public ResourceService()
        {
            _resourceDAO = new ResourceDAO();
        }

        public List<TranslationModel> GetTranslationsByTypeAndPagingInfo(int type, ref PagingInfoModel pagingInfo)
        {
            return _resourceDAO.GetTranslationsByTypeAndPagingInfo(type, ref pagingInfo); ;
        }

        public void UpdateTranslations(List<TranslationModel> updateList)
        {
            _resourceDAO.UpdateTranslations(updateList);
        }

        public List<TranslationModel> GetAllTranslations()
        {
            return _resourceDAO.GetAllTranslations();
        }

        public bool UpdateTranslationItem(TranslationModel item)
        {
            bool updated = _resourceDAO.UpdateTranslationItem(item);

            if (updated == true)
            {
                Lang.UpdateInMemResource(item.Key, LanguageCodes.en.ToString(), item.English);
                Lang.UpdateInMemResource(item.Key, LanguageCodes.vi.ToString(), item.Vietnamese);
            }

            return updated;
        }

        public bool UpdateSitemapEntry(string key)
        {
            return _resourceDAO.UpdateSitemapEntry(key);
        }

        public bool AddSitemapEntry(string key)
        {
            return _resourceDAO.AddSitemapEntry(key);
        }

        public bool RemoveSitemapEntry(string key)
        {
            return _resourceDAO.RemoveSitemapEntry(key);
        }
    }
}
